package com.taptech.doufu.services;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.taptech.doufu.manager.NovelEditManager;
import com.taptech.doufu.util.StringUtil;
import com.taptech.doufu.ui.activity.NewNovelCreateListTosActivity;
import com.taptech.doufu.ui.activity.NovelCreateContentTosActivity;
import com.taptech.doufu.ui.activity.NovelCreateSetActivity;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.bean.MineNovelBean;
import com.taptech.doufu.bean.NovelDraftBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.services.personalcenter.WeiboService;
import com.taptech.doufu.net.httputils.HttpRequestObject;
import com.taptech.doufu.net.httputils.HttpUtil;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class NovelCreateServices
{
    public static final int HANDLE_TYPE_SAVE_TOPIC_NOVEL = 5200;
    public static final int HANDLE_TYPE_MY_DRAFTS = 5201;
    public static final int HANDLE_TYPE_SEND_NOVEL = 5202;
    public static final int HANDLE_TYPE_SAVE_DRAFTS = 5203;
    public static final int HANDLE_TYPE_DEL_DRAFTS = 5204;
    public static final int HANDLE_TYPE_GET_NOVEL_CONTENT = 5205;
    public static final int HANDLE_TYPE_GET_DRAFT_CONTENT = 5206;
    public static final int HANDLE_TYPE_DEL_NOVEL_SECTION = 5208;
    public static final int HANDLE_TYPE_GET_SEXUALITY = 5209;
    public static final int HANDLE_TYPE_CANCEL_TIMESENT= 5210;
    public static final int HANDLE_TYPE_PRE_COLLECT= 5211;
    public static final int HANDLE_TYPE_SET_SUBMIT= 5212;
    public static NovelCreateServices instance = new NovelCreateServices();


    public static NovelCreateServices getInstance()
    {

        return instance;
    }

    /**
     * 修改小说属性
     *
     * @param listener
     * @param id            小说ID
     * @param publishType  可选，发表方式
     * @param isOriginal   可选，原创/同人
     * @param novelSource  可选，同人作品来源
     * @param sexual        可选，性向
     * @param sexualName1  可选，主角A全名
     * @param sexualName2  可选，主角B全名
     */
    public void saveTopicNovel(HttpResponseListener listener, String id, String novel_type, String publishType, String isOriginal, String novelSource,
                               String sexual, String sexualName1, String sexualName2)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> lsit = new LinkedList<>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);

        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        if (isNotNullContent(novel_type))
        {
            value = new BasicNameValuePair("novel_type", novel_type);
            lsit.add(value);
        }else {
            value = new BasicNameValuePair("novel_type", "0");
            lsit.add(value);
        }
        if (isNotNullContent(publishType))
        {
            value = new BasicNameValuePair("publish_type", publishType);
            lsit.add(value);
            Log.i("test", "publish_type:"+publishType);
        }
        if (isNotNullContent(isOriginal))
        {
            value = new BasicNameValuePair("is_original", isOriginal);
            lsit.add(value);
            Log.i("test", "is_original:"+isOriginal);
        }
        if (isNotNullContent(novelSource))
        {
            value = new BasicNameValuePair("novel_source", novelSource);
            lsit.add(value);
            Log.i("test", "novel_source:"+novelSource);
        }
        if (isNotNullContent(sexual))
        {
            value = new BasicNameValuePair("sexuality", sexual);
            lsit.add(value);
            Log.i("test", "sexuality:"+sexual);
        }
        if (isNotNullContent(sexualName1))
        {
            value = new BasicNameValuePair("sexual_name1", sexualName1);
            lsit.add(value);
            Log.i("test", "sexual_name1:"+sexualName1);
        }
        if (isNotNullContent(sexualName2))
        {
            value = new BasicNameValuePair("sexual_name2", sexualName2);
            lsit.add(value);
            Log.i("test", "sexual_name2:"+sexualName2);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }

    /**
     * 修改小说属性
     *
     * @param listener
     * @param id            小说ID
     * @param title         小说标题
     * @param image         可选，JSON，小说封面（{"path": "封面URL", "width": 封面宽度, "height": 封面高度}）
     * @param description  可选，小说简介
     * @param tagsList     可选，数组，小说标签
     * @param finished     可选，是否完结，0默认为未完结
     * @param publishType  可选，发表方式
     * @param isOriginal   可选，原创/同人
     * @param novelSource  可选，同人作品来源
     * @param sexuality        可选，性向
     * @param sexualName1  可选，主角A全名
     * @param sexualName2  可选，主角B全名
     * @param grant_type   可选，授权方式
     */
    public void saveTopicNovel(HttpResponseListener listener, String id, String title, String image, String description, ArrayList<String> tagsList, String finished, String novel_type,
                               String sexuality, String publishType, String isOriginal, String novelSource, String sexualName1, String sexualName2, String grant_type)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> lsit = new LinkedList<>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);
        if (isNotNullContent(title))
        {
            value = new BasicNameValuePair("title", title);
            lsit.add(value);
        }

        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        if (isNotNullContent(image))
        {
            value = new BasicNameValuePair("image", image);
            lsit.add(value);
        }
        if (isNotNullContent(description))
        {
            value = new BasicNameValuePair("description", description);
            lsit.add(value);
        }
        if (tagsList != null)
        {
            setTagValuePair(tagsList, lsit);
        }
        if (isNotNullContent(finished))
        {
            value = new BasicNameValuePair("finished", finished);
            lsit.add(value);
        }
        if (isNotNullContent(novel_type))
        {
            value = new BasicNameValuePair("novel_type", novel_type);
            lsit.add(value);
        }else {
            value = new BasicNameValuePair("novel_type", "0");
            lsit.add(value);
        }
        if (isNotNullContent(sexuality))
        {
            value = new BasicNameValuePair("sexuality", sexuality);
            lsit.add(value);
            Log.i("test", "sexuality:"+sexuality);
        }
        if (isNotNullContent(publishType))
        {
            value = new BasicNameValuePair("publish_type", publishType);
            lsit.add(value);
            Log.i("test", "publish_type:"+publishType);
        }
        if (isNotNullContent(isOriginal))
        {
            value = new BasicNameValuePair("is_original", isOriginal);
            lsit.add(value);
            Log.i("test", "is_original:"+isOriginal);
        }
        if (isNotNullContent(novelSource))
        {
            value = new BasicNameValuePair("novel_source", novelSource);
            lsit.add(value);
            Log.i("test", "novel_source:"+novelSource);
        }
        if (isNotNullContent(sexualName1))
        {
            value = new BasicNameValuePair("sexual_name1", sexualName1);
            lsit.add(value);
            Log.i("test", "sexual_name1:"+sexualName1);
        }
        if (isNotNullContent(sexualName2))
        {
            value = new BasicNameValuePair("sexual_name2", sexualName2);
            lsit.add(value);
            Log.i("test", "sexual_name2:"+sexualName2);
        }
        if (isNotNullContent(grant_type))
        {
            value = new BasicNameValuePair("grant_type", grant_type);
            lsit.add(value);
            Log.i("test", "grant_type:"+grant_type);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }

    /**
     * 修改小说属性
     *
     * @param listener
     * @param id          小说ID
     * @param image       可选，JSON，小说封面（{"path": "封面URL", "width": 封面宽度, "height": 封面高度}）
     * @param description 可选，小说简介
     * @param description2 可选，小说推荐语
     */
    public void saveTopicNovel(HttpResponseListener listener, String id, String image, String description, String novel_type,String description2,int pre_collect)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> list = new LinkedList<>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        list.add(value);

        value = new BasicNameValuePair("pre_collect", String.valueOf(pre_collect));
        list.add(value);
        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            list.add(value);
        }
        if (isNotNullContent(image))
        {
            value = new BasicNameValuePair("image", image);
            list.add(value);
        }
        if (isNotNullContent(description))
        {
            value = new BasicNameValuePair("description", description);
            list.add(value);
        }
        if (isNotNullContent(description2))
        {
            value = new BasicNameValuePair("description2", description2);
            list.add(value);
        }
        if (isNotNullContent(novel_type))
        {
            value = new BasicNameValuePair("novel_type", novel_type);
            list.add(value);
        }else {
            value = new BasicNameValuePair("novel_type", "0");
            list.add(value);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(list);
        HttpUtil.sendPostRequest(request);
    }

    /**
     * 修改小说属性
     *
     * @param listener
     * @param id          小说ID
     * @param title       小说标题
     * @param image       可选，JSON，小说封面（{"path": "封面URL", "width": 封面宽度, "height": 封面高度}）
     * @param description 可选，小说简介
     * @param tagsList    可选，数组，小说标签
     * @param finished    可选，是否完结，0默认为未完结
     */
    public void saveTopicNovel(HttpResponseListener listener, String id, String title, String image, String description, ArrayList<String> tagsList, String finished, String novel_type)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);
        if (isNotNullContent(title))
        {
            value = new BasicNameValuePair("title", title);
            lsit.add(value);
        }

        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        if (isNotNullContent(image))
        {
            value = new BasicNameValuePair("image", image);
            lsit.add(value);
        }
        if (isNotNullContent(description))
        {
            value = new BasicNameValuePair("description", description);
            lsit.add(value);
        }
        if (tagsList != null)
        {
            setTagValuePair(tagsList, lsit);
        }
        if (isNotNullContent(finished))
        {
            value = new BasicNameValuePair("finished", finished);
            lsit.add(value);
        }
        if (isNotNullContent(novel_type))
        {
            value = new BasicNameValuePair("novel_type", novel_type);
            lsit.add(value);
        }else {
            value = new BasicNameValuePair("novel_type", "0");
            lsit.add(value);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }

    /**
     * 修改小说推荐语
     *
     * @param listener
     * @param id          小说ID
     * @param description2
     */
    public void saveNovelRecommendDesc(HttpResponseListener listener, String id,  String description2)
    {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);


        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        if (isNotNullContent(description2))
        {
            value = new BasicNameValuePair("description2", description2);
            lsit.add(value);
        }

        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }


    public void saveNovelPreCollect(HttpResponseListener listener, String id,  int pre_collect) {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_PRE_COLLECT);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);


        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        value = new BasicNameValuePair("pre_collect", String.valueOf(pre_collect));
        lsit.add(value);

        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }


    /**
     * 提交审核
     * @param listener
     * @param id
     */
    public  void submitNovelSet(HttpResponseListener listener,String id){
        HttpRequestObject requestObject = new HttpRequestObject();
        requestObject.setHandleType(HANDLE_TYPE_SET_SUBMIT);
        List<NameValuePair> list = new LinkedList<>();
        NameValuePair vale = new BasicNameValuePair("id",id);
        list.add(vale);
        vale = new BasicNameValuePair("novel_info_submit","1");
        list.add(vale);
        requestObject.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        requestObject.setListener(listener);
        requestObject.setData(list);
        HttpUtil.sendPostRequest(requestObject);
    }

    /**
     * 修改小说属性
     *
     * @param listener
     * @param id          小说ID
     * @param title       小说标题
     * @param image       可选，JSON，小说封面（{"path": "封面URL", "width": 封面宽度, "height": 封面高度}）
     * @param description 可选，小说简介
     * @param tagsList    可选，数组，小说标签
     * @param finished    可选，是否完结，0默认为未完结
     * @param isVertical
     */
    public void saveTopicNovel(HttpResponseListener listener, String id, String title, String image, String description, ArrayList<String> tagsList, String finished,boolean isVertical) {

        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_TOPIC_NOVEL);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;

        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);
        if (isNotNullContent(title))
        {
            value = new BasicNameValuePair("title", title);
            lsit.add(value);
        }

        if (isNotNullContent(id))
        {
            value = new BasicNameValuePair("id", id);
            lsit.add(value);
        }
        if (isNotNullContent(image))
        {
            if (isVertical) {
                value = new BasicNameValuePair("image_w", image);
            }else{
                value = new BasicNameValuePair("image", image);
            }
            lsit.add(value);
        }
        if (isNotNullContent(description))
        {
            value = new BasicNameValuePair("description", description);
            lsit.add(value);
        }
        if (tagsList != null)
        {
            setTagValuePair(tagsList, lsit);
        }
        if (isNotNullContent(finished))
        {
            value = new BasicNameValuePair("finished", finished);
            lsit.add(value);
        }

        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/saveTopic");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);

    }

    private void setTagValuePair(ArrayList<String> tagsList, List<NameValuePair> lsit)
    {
        NameValuePair value;
        for (int i = 0; i < tagsList.size(); i++)
        {
            if (tagsList.get(i) != null && !"".equals(tagsList.get(i)))
            {
                value = new BasicNameValuePair("tags[]", tagsList.get(i));
                lsit.add(value);
            }
        }
    }

    /**
     * 我的草稿
     *
     * @param listener
     * @param object_id （小说ID）
     */
    public void loadMyDrafts(HttpResponseListener listener, String object_id)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_MY_DRAFTS);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/drafts/myDrafts?object_id=" + object_id + "&type=" + Constant.OBJECT_TYPE_NOVEL);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }



    /**
     * 保存小说章节，发送到微博
     *
     * @param listener
     * @param topic_id      小说ID。
     * @param article_id    可选，章节ID，若有，则为修改章节。
     * @param article_title 章节标题
     * @param text          内容
     */
    public void saveNovelChapter(Activity activity , HttpResponseListener listener,
                                 String topic_id, String article_id, String article_title,
                                 String text, boolean isTongbuWeibo, String extral_text,String draftId) {
        saveNovelChapter(activity,listener,topic_id,article_id,article_title,text,isTongbuWeibo,extral_text,false,draftId);
    }

    /**
     * 保存小说章节，发送到微博
     *
     * @param listener
     * @param topic_id      小说ID。
     * @param article_id    可选，章节ID，若有，则为修改章节。
     * @param article_title 章节标题
     * @param text          内容
     * @param isDirect      直接发布
     */
    public void saveNovelChapter(Activity activity , HttpResponseListener listener,
                                 String topic_id, String article_id, String article_title,
                                 String text, boolean isTongbuWeibo, String extral_text,boolean isDirect,String draftId) {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SEND_NOVEL);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("object_type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);
        value = new BasicNameValuePair("topic_id", topic_id);
        lsit.add(value);
        if (isNotNullContent(article_id))
        {
            value = new BasicNameValuePair("article_id", article_id);
            lsit.add(value);
        }

        if (!TextUtils.isEmpty(draftId)) {
            value = new BasicNameValuePair("draft_id", draftId);
            lsit.add(value);
        }

        if (!isDirect) {
            value = new BasicNameValuePair("test","1");
            lsit.add(value);
        }

        value = new BasicNameValuePair("article_title", article_title);
        lsit.add(value);
        value = new BasicNameValuePair("text", text);
        lsit.add(value);
        value = new BasicNameValuePair("apply", "1");
        lsit.add(value);
        value = new BasicNameValuePair("extral_text", extral_text);
        lsit.add(value);
        if (isTongbuWeibo)
        {
            if (WeiboService.getInstance().mAccessToken.isSessionValid()){
//                value = new BasicNameValuePair("sina_key", WeiboService.getInstance().mAccessToken.getToken());
                lsit.add(value);
            }else {
                WeiboService.getInstance().bindWebiAccount(activity);
            }

        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/novel/save_chapter");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);
    }

    /**
     * 存草稿
     *
     * @param object_id  草稿ID，新建时为空，编辑时必填
     * @param article_id 对象ID
     * @param content
     */
    public void loadSaveNovelDrafts(HttpResponseListener listener, String object_id, String article_id, String content, String description, String extral_text ,String date,boolean publish)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_SAVE_DRAFTS);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("object_id", object_id);
        lsit.add(value);
        value = new BasicNameValuePair("content", content);
        lsit.add(value);
        value = new BasicNameValuePair("type", Constant.OBJECT_TYPE_NOVEL + "");
        lsit.add(value);
        value = new BasicNameValuePair("description", description);
        lsit.add(value);
        value = new BasicNameValuePair("extral_text", extral_text);
        lsit.add(value);
        if (publish) {
            value = new BasicNameValuePair("public", "1");
            lsit.add(value);
        }
        if (isNotNullContent(article_id))
        {
            value = new BasicNameValuePair("id", article_id);
            lsit.add(value);
        }
        if(StringUtil.stringLength(date)){
            value = new BasicNameValuePair("timer_at", date);
            lsit.add(value);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/drafts/save");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);
    }

    /**
     * 删除草稿
     *
     * @param listener
     * @param id
     */
    public void loadDelDrafts(HttpResponseListener listener, String id)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_DEL_DRAFTS);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("id", id);
        lsit.add(value);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/drafts/remove");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);
    }
    /**
     * 取消定时发布
     *
     * @param listener
     * @param id
     */
    public void cancelTimeSent(HttpResponseListener listener, String id)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_CANCEL_TIMESENT);
        List<NameValuePair> lsit = new LinkedList<NameValuePair>();
        NameValuePair value;
        value = new BasicNameValuePair("id", id);
        lsit.add(value);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/drafts/clear_timer");
        request.setListener(listener);
        request.setData(lsit);
        HttpUtil.sendPostRequest(request);
    }
    private boolean isNotNullContent(String content)
    {
        return content != null;
    }

    /**
     * @param listener
     * @param object_id 章节ID JSONObject jsonObject = (JSONObject) response.getData();
     *                  detail = jsonObject.getJSONObject("detail"); contentBean = new
     *                  HomeTopBean(); contentBean.setJson(detail);
     */
    public void loadNovelUnitContent(HttpResponseListener listener, String object_id, String type)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_GET_NOVEL_CONTENT);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/view/" + object_id + "?with_ids=" + 1 + "&type=" + type);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    /**
     * 返回章节详情内容
     *
     * @param listener
     * @param object_id 章节ID
     */
    public void loadDraftUnitContent(HttpResponseListener listener, String object_id)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_GET_DRAFT_CONTENT);
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/drafts/draft?id=" + object_id);
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    /**
     * 获取性向信息
     * @param listener 回调接口
     */
    public void getSexuality(HttpResponseListener listener){
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_GET_SEXUALITY);
        request.setUrl(Constant.HOST_NAME_SECOND + "/entrance_item/work_options");
        request.setListener(listener);
        HttpUtil.sendGetRequest(request);
    }

    public void deleteNovelSectionRequest(HttpResponseListener listener, String sectionId)
    {
        HttpRequestObject request = new HttpRequestObject();
        request.setHandleType(HANDLE_TYPE_DEL_NOVEL_SECTION);
        List<NameValuePair> list = new LinkedList<NameValuePair>();
        NameValuePair value;
        if (sectionId != null)
        {
            value = new BasicNameValuePair("id", sectionId);
            list.add(value);
        }
        request.setUrl(Constant.HOST_NAME_SECOND + "/index.php/post/removeTopicReply");
        request.setListener(listener);
        request.setData(list);
        HttpUtil.sendPostRequest(request);
    }

    static public void enterNovelCreateList(Context context, String novelId, String novelName)
    {
        Intent intent = new Intent(context, NewNovelCreateListTosActivity.class);
        intent.putExtra(Constant.NOVEL_ID, novelId);
        intent.putExtra(Constant.NOVEL_NAME, novelName);
        context.startActivity(intent);
    }

    static public void enterNovelCreateContentTos(Context context, int flag, String title, String id, String topicId, String articleId, ArrayList<String> novelIds, String icon)
    {

        HomeTopBean homeTopBean = new HomeTopBean();
        homeTopBean.setTitle(title);
        homeTopBean.setId(id);
        homeTopBean.setTopicId(topicId);
        homeTopBean.setArticle_id(articleId);
        if(!TextUtils.isEmpty(icon)){
            homeTopBean.setIcon_url(icon);
        }
        Intent intent = new Intent(context, NovelCreateContentTosActivity.class);
        intent.putExtra(Constant.DATA, homeTopBean);
        if (novelIds != null)
        {
            intent.putStringArrayListExtra("NOVELIDS", novelIds);
        }
        intent.putExtra(Constant.FLAG, flag);
        Activity activity = (Activity) context;
        activity.startActivityForResult(intent, NewNovelCreateListTosActivity.REFRESH_REQUEST_CODE);
    }

    static public void enterNovelDraftCreate(Context context, NovelDraftBean novelDraftBean, ArrayList<String> novelIds,String publish)
    {
        Intent intent = new Intent(context, NovelCreateContentTosActivity.class);
        intent.putExtra(Constant.DATA, novelDraftBean);
        if (novelIds != null) {
            intent.putStringArrayListExtra("NOVELIDS", novelIds);
        }
        if(novelDraftBean.getUser() != null && !TextUtils.isEmpty(novelDraftBean.getUser().getIcon())){
            intent.putExtra(Constant.IMAGE, novelDraftBean.getUser().getIcon());
        }
        if (!TextUtils.isEmpty(publish)) {
            intent.putExtra("publish", publish);
        }
        intent.putExtra(Constant.FLAG, NovelEditManager.NOVEL_DRAFTS);
        Activity activity = (Activity) context;
        activity.startActivityForResult(intent, NewNovelCreateListTosActivity.REFRESH_REQUEST_CODE);


    }

    static public void enterNovelSetting(Context context, MineNovelBean bean)
    {
        Intent intent = new Intent(context, NovelCreateSetActivity.class);
        intent.putExtra(Constant.DATA, bean);
        Activity activity = (Activity) context;
        activity.startActivityForResult(intent, NewNovelCreateListTosActivity.REFRESH_REQUEST_CODE);
    }
}
